package com.vogue.supplymall.order.config;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.vogue.configs.startup.SpringContext;
import com.vogue.sprakka.ActorStarter;
import com.vogue.sprakka.BeanFieldProcessor;
import com.vogue.sprakka.remote.ExportServerInfo;
import com.vogue.sprakka.remote.ServerInfo;
import com.vogue.supplymall.account.shiro.filter.MallAuthenticationFilter;
import com.vogue.supplymall.account.shiro.filter.WholeAuthenticationFilter;
import com.vogue.supplymall.common.config.BaseAppConfig;
import com.vogue.supplymall.common.config.JacksonConvert;
import com.vogue.supplymall.common.domain.tool.GsonUtils;
import com.vogue.supplymall.common.domain.tool.MessageSourceUtils;
import com.vogue.supplymall.common.domain.tool.PackageUtil;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

/**
 * The type Order config.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-10
 */
@Configuration
@ComponentScan(value = {"com.vogue.supplymall.common.domain.tool",
//        "com.vogue.supplymall.common.domain.dto",
        "com.vogue.supplymall.payment.dto",
        "com.vogue.supplymall.payment.tools",
        "com.vogue.supplymall.common.config",
        "com.vogue.supplymall.account.domain",
        "com.vogue.supplymall.shop.domain",
        "com.vogue.supplymall.match.domain",
        "com.vogue.supplymall.upload.domain",
        "com.vogue.supplymall.admin.business.domain.dao",
        "com.vogue.supplymall.admin.business.domain.service",
        "com.vogue.supplymall.cross.domain"})
@ComponentScan("com.vogue.supplymall.shop.common")
@ComponentScan("com.vogue.supplymall.order.domain.biz")
@ComponentScan("com.vogue.supplymall.order.domain.service")
@ComponentScan("com.vogue.supplymall.payment.api")
@ComponentScan("com.vogue.supplymall.common.domain.dto")
@MapperScan({"com.vogue.supplymall.account.domain.mapper",
        "com.vogue.supplymall.order.domain.mapper",
        "com.vogue.supplymall.match.domain.mapper",
        "com.vogue.supplymall.shop.domain.mapper",
        "com.vogue.supplymall.admin.business.domain.mapper",
        "com.vogue.supplymall.cross.domain.mapper"})
@ImportResource(locations = {"classpath:order-context.xml", "classpath:base-context.xml"})
@Import(SpringContext.class)
public class OrderConfig extends BaseAppConfig {

    private static final Logger LOGGER_ORDERCONFIG = LoggerFactory.getLogger(OrderConfig.class);

//    @Resource(name="orderPropertiesConfig")
//    private PropertiesConfig propertiesConfig;
    
    @Bean
    public FilterRegistrationBean regAuth(MallAuthenticationFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(filter);
        registration.setEnabled(false);
        return registration;
    }

    @Bean
    public FilterRegistrationBean regWhole(WholeAuthenticationFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(filter);
        registration.setEnabled(false);
        return registration;
    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        JacksonConvert.convert(converters);
    }

    //    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new OrderInterceptor()).addPathPatterns("/**");
//        super.addInterceptors(registry);
//    }
    @Bean(name = "messageSourceUtils")
    public MessageSourceUtils messageSourceUtils() {
        return new MessageSourceUtils("i18n/ordermessages");
    }
}
